package com.sword.test.testcase.demo;

import com.sword.commons.okhttp.HttpResponse;
import com.sword.test.testcase.TestCase;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpDownload;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpGet;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpHead;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpOptions;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpPatch;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpPost;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpPut;
import com.sword.woodpecker.autotest.framework.object.apiobject.HttpUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;


/**
 * 类描述:〈使用内置的请求类来发送Http请求〉
 *
 * @author: xujinjian
 */
public class Demo3TC extends TestCase {

    /**
     * 发送Get请求类
     */
    @Autowired
    protected HttpGet httpGet;

    /**
     * 发送Post请求类
     */
    @Autowired
    protected HttpPost httpPost;

    /**
     * 发送Put请求类
     */
    @Autowired
    protected HttpPut httpPut;

    /**
     * 发送Download请求类
     */
    @Autowired
    protected HttpDownload httpDownload;

    /**
     * 发送Upload请求类
     */
    @Autowired
    protected HttpUpload httpUpload;

    /**
     * 发送Head请求类
     */
    @Autowired
    protected HttpHead httpHead;

    /**
     * 发送Patch请求类
     */
    @Autowired
    protected HttpPatch httpPatch;

    /**
     * 发送Options请求类
     */
    @Autowired
    protected HttpOptions httpOptions;

    private String host = "http://www.baidu.com";


    @Test
    public void test1() {
        String url = "/s";
        String param = "ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=testtest&fenlei=256&oq=%25E8%2587%25AA%25E5%258A%25A8%25E5%258C%2596%25E6%25B5%258B%25E8%25AF%2595&rsv_pq=8431637f00014d34&rsv_t=ea57G2yAdcAtfdM9gw5UiplinP1m07tGwsNsiIexzUJHAtHC7vQv0agj1eg&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&inputT=8137&rsv_sug3=35&rsv_sug1=39&rsv_sug7=101&rsv_sug4=8830";
        //httpGet类中，含有多种get请求方式，具体的看方法参数，选择适合自己的
        HttpResponse httpResponse = httpGet.get(host + url, param);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test2() {
        //httpPost类中，含有多种post请求方式，具体的看方法参数，选择适合自己的
        //没有现成的POST请求接口，这里随便传个null
        HttpResponse httpResponse = httpPost.post(null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test3() {
        //httpPut类中，含有多种put请求方式，具体的看方法参数，选择适合自己的
        //没有现成的put请求接口，这里随便传个null
        HttpResponse httpResponse = httpPut.put(null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test4() {
        //httpDownload类中，含有多种download请求方式，具体的看方法参数，选择适合自己的
        //没有现成的download请求接口，这里随便传个null
        HttpResponse httpResponse = httpDownload.download(null, null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
    }


    @Test
    public void test5() {
        //httpUpload类中，含有多种upload请求方式，具体的看方法参数，选择适合自己的
        //没有现成的upload请求接口，这里随便传个null
        HttpResponse httpResponse = httpUpload.upload(null, (String) null, null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test6() {
        //httpPatch类中，含有多种patch请求方式，具体的看方法参数，选择适合自己的
        //没有现成的patch请求接口，这里随便传个null
        HttpResponse httpResponse = httpPatch.patch(null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test7() {
        //httpHead类中，含有多种head请求方式，具体的看方法参数，选择适合自己的
        //没有现成的head请求接口，这里随便传个null
        HttpResponse httpResponse = httpHead.head(null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
        if (httpResponse.getCode() == 200) {
            logger.info("请求响应Body为[{}]", httpResponse.getBody());
        }
    }


    @Test
    public void test8() {
        //httpOptions类中，含有多种options请求方式，具体的看方法参数，选择适合自己的
        //没有现成的options请求接口，这里随便传个null
        HttpResponse httpResponse = httpOptions.options(null);
        logger.info("请求响应状态码为[{}]", httpResponse.getCode());
    }


}
